#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
    // 下层
    int fd = open("bite", O_RDWR | O_CREAT | O_TRUNC, 0666);
    if (fd < 0)
    {
        perror("open");
    }
    const char *buf = "I like linux!";
    write(fd, buf, strlen(buf));

    lseek(fd, 0, SEEK_SET);

    char buffer[32];
    read(fd, buffer, sizeof(buffer));

    printf("%s\n", buffer);

    close(fd);

    // 上层
    //FILE * fp = fopen("bite", "w+");
    //if (fp == NULL)
    //{
    //    perror("bite");
    //}

    //const char *buf = "linux so easy!";
    //fputs(buf, fp);
    //// 完成写入操作后，光标在文件末尾
    //rewind(fp);

    //char buffer[32];
    //fgets(buffer, sizeof(buffer), fp);
    //fprintf(stdout, "%s\n", buffer);
    //
    //fclose(fp);
    
    return 0;
}
